import datetime

import datamodel
from settings import Settings

def checkNotFlooding(self, isreply):
  post = datamodel.Post.all().filter('ip = ', self.request.remote_addr)
  if isreply:
    limit = Settings.SECONDS_BETWEEN_REPLIES
  else:
    limit = Settings.SECONDS_BETWEEN_NEW_THREADS
  post = post.order('-date').get()
  
  if post:
    timedifference = (datetime.datetime.now() - post.date)
    if timedifference.seconds < limit:
      return False

  return True

def checkNotBanned(self, address):
  ban = datamodel.Ban.all().filter('ip = ', address).get()
  
  if ban:
    return False

  return True
